package com.hbnu.iostream;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;

/**
 * @author kittychen
 * @date 2025-09-30 10:54
 */
public class OutputStreamDemo02 {
    public static void main(String[] args) {
        String path = "E:" + File.separator + "2309" + File.separator + "test1.txt";
        File file = new File(path);

        OutputStream outputStream = null;

        try {
            outputStream = new FileOutputStream(file, true);

            String content = "\r\n国庆收假后，好多课需要补.....";

            byte[] bytes = content.getBytes();

            // 一个字节一个字节的往磁盘文件中写数据
            // for (int i = 0; i < bytes.length; i++) {
            //     outputStream.write(bytes[i]);
            // }
            for (byte data : bytes) {
                outputStream.write(data);
            }

            System.out.println("数据写入成功");
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                if (outputStream != null) {
                    outputStream.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }


}
